package model.entity.container;

import model.exceptions.InvalidNameException;
import reports.visitor.IVisitor;

/**
 * Describes a top-level <code>ProductContainer</code> that is a physical storage location.
 * 
 * @author Trevor Dixon, Ryan Cheatham
 */
public class StorageUnit extends ProductContainer implements Comparable<StorageUnit>
{
  private static final long serialVersionUID = -1857339114733975957L;

  /**
   * Constructs a new StorageUnit with the given name.
   * 
   * @param name
   *          The name of the new StorageUnit.
   * @throws InvalidNameException
   *           if the given name is invalid.
   */
  public StorageUnit(String name) throws InvalidNameException
  {
    super(name);
    setId(-1);
  }

  @Override
  public boolean equals(Object obj)
  {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (!(obj instanceof StorageUnit))
      return false;
    StorageUnit other = (StorageUnit) obj;
    if (name == null)
    {
      if (other.name != null)
        return false;
    }
    else if (!name.equals(other.name))
      return false;
    return true;
  }

  @Override
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    builder.append("StorageUnit [name='");
    builder.append(name);
    builder.append("']");
    return builder.toString();
  }

  @Override
  public int compareTo(StorageUnit o)
  {
    return name.compareToIgnoreCase(o.name);
  }

  @Override
  public StorageUnit getStorageUnit()
  {
    return this;
  }

  @Override
  public void preOrderAccept(IVisitor visitor)
  {
    visitor.visit(this);
  }

  @Override
  public void postOrderAccept(IVisitor visitor)
  {
    visitor.visit(this);
  }
}
